import asyncio
import random


async def random_num_gen(delay,start,end):
    while True:
        yield random.randint(start,end)
        await asyncio.sleep(delay)


async def main():
    #通过 async for 来 调用生成器
    async for i in random_num_gen(2,1,6):
        print(i)


async def gen_coro():
    yield 1
    yield 2
    yield 3

async def main_assend():
    coro = gen_coro()
    print(await coro.asend(None))
    print(await coro.asend(None))

async def main_():
    loop = asyncio.get_event_loop()
    try:
        pass
    except:
        pass
    finally:
        loop.shutdown_asyncgens()

if __name__ == '__main__':
    asyncio.run(main_assend())